package com.admission.web.admin;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.admission.model.GroupRegister;
import com.admission.model.OrderTemp;
import com.admission.service.GroupRegisterManager;
import com.admission.util.PageUtils;
import com.admission.web.CrudActionSupport;

@Namespace("/admin")
public class GroupRegisterAdminAction extends CrudActionSupport<GroupRegister> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3206732755613397502L;

	private Page<GroupRegister> page = new Page<GroupRegister>(PageUtils.DEFAULT_PAGE_SIZE);
	private GroupRegisterManager groupRegisterManager;
	private String id;
	private GroupRegister entity;
	private String searchMobile;
	
	public Page<GroupRegister> getPage() {
		return page;
	}

	public void setPage(Page<GroupRegister> page) {
		this.page = page;
	}

	public GroupRegisterManager getGroupRegisterManager() {
		return groupRegisterManager;
	}

	public void setGroupRegisterManager(GroupRegisterManager groupRegisterManager) {
		this.groupRegisterManager = groupRegisterManager;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public GroupRegister getEntity() {
		return entity;
	}

	public void setEntity(GroupRegister entity) {
		this.entity = entity;
	}

	public void setSearchMobile(String searchMobile) {
		this.searchMobile = searchMobile;
	}
	
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		List<PropertyFilter> filters = PropertyFilter
		.buildFromHttpRequest(Struts2Utils.getRequest());
		if (!StringUtils.isEmpty(searchMobile)) {
			PropertyFilter p1 = new PropertyFilter("EQS_mobile",
					searchMobile);
			filters.add(p1);
		}
		page=groupRegisterManager.getPageByFilter(page, filters);
		return "list";
	}

	@Override
	protected void prepareModel() throws Exception {
		if (StringUtils.isEmpty(id)) {
			entity = new  GroupRegister();
		} else {
			entity = groupRegisterManager.getGroupRegisterById(id);
		}
	}

	@Override
	public String save() throws Exception {
		try{
			groupRegisterManager.save(entity);
		} catch (Exception e) {
		   this.addActionMessage("操作失败，请重新操作");
	    }
		return this.list();
	}

	public String resetPwd() throws Exception{
		try{
			entity = groupRegisterManager.getGroupRegisterById(id);
			entity.setPassword("000000");
			groupRegisterManager.save(entity);
			this.addActionMessage("修改成功");
		} catch (Exception e) {
		   this.addActionMessage("操作失败，请重新操作");
	    }
		return this.list();
	}
	
	public GroupRegister getModel() {
		return entity;
	}

}
